package com.gxar.marketdelivery.interfaces.assembler;

import com.gxar.marketdelivery.infra.dao.entity.DeliveryMaterialEntity;
import com.gxar.marketdelivery.shared.model.DeliveryMaterialModel;
import com.gxar.marketdelivery.shared.utils.AssemblerUtils2;
import com.gxar.marketdelivery.shared.utils.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author nice
 * @version 1.0
 * @created 2023/7/21.
 */
public class DeliveryMaterialConverter {

    public static DeliveryMaterialModel convertToModel(DeliveryMaterialEntity entity) {
        if (entity == null) {
            return null;
        }
        DeliveryMaterialModel model = new DeliveryMaterialModel();
        AssemblerUtils2.assemble(entity, model);
        return model;
    }

    public static List<DeliveryMaterialModel> convertToModelList(List<DeliveryMaterialEntity> entities) {
        if (CollectionUtils.isEmpty(entities)) {
            return Collections.emptyList();
        }
        return entities.stream().map(DeliveryMaterialConverter::convertToModel).filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
}
